﻿using PenguinForce.Entities;
using Microsoft.Xna.Framework;

namespace PenguinForce.FlockBehaviors
{
    /// <summary>
    /// AlignBehavior is a Behavior that makes an animal move in the same
    /// direction that the other Animal it sees is
    /// </summary>
    public class AlignBehavior : Behavior
    {
        #region Initialization
        public AlignBehavior(Entity animal)
            : base(animal)
        {
        }
        #endregion

        #region Update

        /// <summary>
        /// AlignBehavior.Update infuences the owning animal to move in same the 
        /// direction as the otherAnimal that it sees.
        /// </summary>
        /// <param name="otherAnimal">the Animal to react to</param>
        /// <param name="aiParams">the Behaviors' parameters</param>
        public override void Update(Entity otherAnimal, AIParameters aiParams)
        {
            base.ResetReaction();

            if (otherAnimal != null)
            {
                reacted = true;
                reaction = otherAnimal.Direction * aiParams.perMemberWeight * (Vector2.Distance(Animal.Location, otherAnimal.Location) / 1000.0f);
            }
        }
        #endregion
    }
}